package com.letv.whatslive.model.convert;

import com.letv.whatslive.common.utils.ObjectUtils;
import com.letv.whatslive.model.Department;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by Administrator on 2016/3/3.
 */
public class DepartmentConvert {
    public static DBObject castDepartmentToDBObject(Department department) {
        DBObject dbo = new BasicDBObject();
        if (department.getId() != null) {
            dbo.put("_id", department.getId());
        }
        dbo.put("name", ObjUtils.ifNull(department.getName(), ""));
        return dbo;
    }
    public static Department castDBObjectToDepartment(DBObject dbObject){
        if(dbObject!=null){
            Department department=new Department();
            department.setId(ObjectUtils.toLong(dbObject.get("_id")));
            department.setName(ObjectUtils.toString(dbObject.get("name")));
            return department;
        }else{
            return null;
        }
    }
}
